using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace FrtSvrGPRS
{
    public partial class IniFile
    {
        public IniFile()
        {
        }

        string IniFileName;

        [DllImport("kernel32.dll")]
        private extern static int GetPrivateProfileStringA(string segName, string keyName, string sDefault, StringBuilder buffer, int nSize, string fileName);
        [DllImport("kernel32.dll")]
        private extern static int WritePrivateProfileStringA(string segName, string keyName, string sValue, string fileName);
        
        public IniFile(string Filename)
        {
            IniFileName = Filename;
        }

        public string ReadIni(string Section, string Key, string Default)
        {
            StringBuilder buffer = new StringBuilder(65535);
            GetPrivateProfileStringA(Section, Key, Default, buffer, buffer.Capacity, IniFileName);
            return buffer.ToString();
        }

        public void WriteIni(string Section, string Key, string strValue)
        {
            if (strValue != null)
                WritePrivateProfileStringA(Section, Key, strValue.ToString(), IniFileName);
            else 
            	WritePrivateProfileStringA(Section, Key, null, IniFileName);
        }

    }
}

